{extend name="public/base" /}
{block name="title"}广告管理{/block} {block name="main"}

<blockquote class="layui-elem-quote e-quoteBox-tip">
    
    广告位名称：<b>{$adposition['name']}</b> &nbsp; ; &nbsp;&nbsp;
    广告图片尺寸建议：<b>宽{$adposition['width']} * 高{$adposition['height']}像素(px)</b>
    
</blockquote>
<blockquote class="layui-elem-quote quoteBox e-quoteBox">
    <form class="layui-form " action="" method="GET">        
        <input type="hidden" name="pid" value="{$pid}" />
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status">
                    <option value=""  {$where['status']==''? 'selected': ''}>全部</option>
                    <option value="1" {$where['status']==1? 'selected': ''}>正常</option>
                    <option value="2" {$where['status']==2? 'selected': ''}>关闭</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn search_btn" id="savebtn" lay-submit="">搜索</button>
            <a href="/set/ad/add/pid/{$pid}" class="layui-btn layui-btn-normal addNews_btn">添加广告</a>
            <a href="/set/ad/position" class="layui-btn layui-btn-primary">返回广告位管理</a>
        </div>
    </form>
</blockquote>
<form class="layui-form">
    <table cellspacing="0" cellpadding="0" border="0" style="width: 100%;" class="layui-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>排序</th>
                <th>名称</th>
                <th>广告图片</th>
                <th>跳转地址</th>
                <th style="width: 80px;">状态</th>
                <th class="layui-table-fixed layui-table-fixed-r">操作</th>
            </tr>
        </thead>
        <tbody>
            {if condition="$data['msg']"}
                <tr class="td_center"><td colspan="10">{$data['msg']}</td></tr>
            {/if}
            {volist name="data['list']" id="item"}
            <tr class="nodelist depth01">
                <td class="td_left">
                    <div class="layui-table-cell ">{$item['id']}</div>
                </td>
                <td class="td_left">
                    <div class="layui-table-cell ">{$item['sort']}</div>
                </td>
                <td class="td_left">
                    <div class="layui-table-cell ">{$item['name']}</div>
                </td>
                <td class="td_left" style="padding: 2px;">
                    <div class="layui-table-cell " style="padding: 2px;">
                        <img  src="{$item['pic']}"/>
                    </div>
                </td>
                <td class="td_left">
                    <div class="layui-table-cell ">{$item['url']}</div>
                </td>
                <td class="td_left">
                    <div class="layui-table-cell layui-inline" style="height:auto;">
                        <input lay-filter="status" type="checkbox" {$item[ 'status']==1? 'checked': ''} data-id="{$item['id']}" lay-skin="switch" lay-text="正常|关闭">
                    </div>
                </td>
                <td class="td_center">
                    <div class="layui-btn-group">
                    <a href="/set/ad/edit/id/{$item['id']}" class="layui-btn layui-btn-sm">编辑</a>
                    </div>
                </td>
            </tr>
            {/volist}
        </tbody>
    </table>
</form>
{$showpage|raw} 

{/block} {block name="script"}
<script>
layui.use(['form'], function (form) {
    form.on('switch(status)', function (data) {
        var id = $(data.elem).data("id");
        var ischecked = data.elem.checked;
        $.post("/set/ad/editstatus",{id:id},function(ret){
            if(ret.code!=1){
                layer.msg(ret.msg);
                if(ischecked){
                    $(data.elem).prop("checked",false);
                    $(data.othis).removeClass("layui-form-onswitch").find("em").text("关闭");
                }else{
                    $(data.elem).prop("checked",true);
                    $(data.othis).addClass("layui-form-onswitch").find("em").text("正常");
                }
            }
        })
        return false;
    });
});
</script> {/block}